package com.ruoyi.project.newhope.warning.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.newhope.warning.domain.NewHopeWarning;
import com.ruoyi.project.newhope.warning.service.INewHopeWarningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 报警记录Controller
 * 
 * @author ruoyi
 * @date 2021-02-08
 */
@Controller
@RequestMapping("/api/newhope/warning")
public class NewHopeWarningController extends BaseController
{

    @Autowired
    private INewHopeWarningService newHopeWarningService;

    /**
     * 查询报警记录列表
     */
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(NewHopeWarning newHopeWarning)
    {
        startPage();
        List<NewHopeWarning> list = newHopeWarningService.selectNewHopeWarningList(newHopeWarning);
        return getDataTable(list);
    }

    /**
     * 查询报警记录列表all
     */
    @GetMapping("/getAll")
    @ResponseBody
    public AjaxResult getAll(NewHopeWarning newHopeWarning)
    {
        List<NewHopeWarning> list = newHopeWarningService.selectNewHopeWarningList(newHopeWarning);
        return AjaxResult.success(list);
    }

    /**
     * 查询一条报警记录
     */
    @GetMapping("/getOne")
    @ResponseBody
    public AjaxResult getOne()
    {
        NewHopeWarning warning = newHopeWarningService.selectNewHopeWarningOne();
        return AjaxResult.success(warning);
    }

    /**
     * 新增保存报警记录
     */
    @Log(title = "报警记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody NewHopeWarning newHopeWarning)
    {
        return toAjax(newHopeWarningService.insertNewHopeWarning(newHopeWarning));
    }

    /**
     * 修改报警记录
     */
    @GetMapping("/edit/{id}")
    @ResponseBody
    public NewHopeWarning edit(@PathVariable("id") Long id)
    {
        NewHopeWarning newHopeWarning = newHopeWarningService.selectNewHopeWarningById(id);
        return newHopeWarning;
    }

    /**
     * 修改保存报警记录
     */
    @Log(title = "报警记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody NewHopeWarning newHopeWarning)
    {
        return toAjax(newHopeWarningService.updateNewHopeWarning(newHopeWarning));
    }

    /**
     * 删除报警记录
     */
    @Log(title = "报警记录", businessType = BusinessType.DELETE)
    @GetMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String id)
    {
        return toAjax(newHopeWarningService.deleteNewHopeWarningByIds(id));
    }
}
